/** 
* All Rights Reserved , Copyright (C) 2021 , 青岛鼎信通讯股份有限公司
* 
* SdDataBoardCustomizeRecordService
* SD数据看板自定义记录表
* 
* 修改纪录
* 2021-12-23 版本：1.0 houyuhang 创建。
* @version 版本：1.0
* @author 作者：houyuhang
* 创建日期：2021-12-23
*/
package com.topscomm.gpm.service.impl;

import com.topscomm.cbo.pojo.CboOrgEntity;
import com.topscomm.cbo.pojo.CboRoleEntity;
import com.topscomm.cbo.service.impl.CboOrgService;
import com.topscomm.cbo.service.impl.CboRoleService;
import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.gpm.pojo.GpmDataBoardComponentAchivesEntity;
import com.topscomm.tap.common.DatacodeCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.topscomm.gpm.service.IGpmDataBoardCustomizeRecordService;
import com.topscomm.gpm.service.impl.auto.GpmDataBoardCustomizeRecordServiceAuto;

import java.util.List;
import java.util.Map;

@Service(value = "gpmDataBoardCustomizeRecordService")
@Scope(value = "singleton")
public class GpmDataBoardCustomizeRecordService extends GpmDataBoardCustomizeRecordServiceAuto implements IGpmDataBoardCustomizeRecordService {
    @Autowired
    private GpmDataBoardComponentAchivesService gpmDataBoardComponentAchivesService;

    @Autowired
    private CboOrgService cboOrgService;

    @Autowired
    private CboRoleService cboRoleService;

    /**
     * @author: wudaliang
     * @date: 2020-12-29
     * @param mapRow
     * @description:设置字段显示值
     * @modify:
     */
    @Override
    public void setDispFields(Map<String, Object> mapRow, DatacodeCache datacodeCache) {
        super.setDispFields(mapRow, datacodeCache);
        String temp;
        if (mapRow.get("recordlevel") != null) {
            temp = mapRow.get("recordlevel").toString();
            mapRow.put("disprecordlevel", datacodeCache.getValueDynamic("MpmRecordLevel", temp, "code", "name"));
        }
        if (mapRow.get("position") != null) {
            temp = mapRow.get("position").toString();
            mapRow.put("dispposition", datacodeCache.getValueDynamic("MpmPosition", temp, "code", "name"));
        }
        if (mapRow.get("componentid") != null) {
            temp = mapRow.get("componentid").toString();
            GpmDataBoardComponentAchivesEntity entity = gpmDataBoardComponentAchivesService
                    .queryById(temp);
            mapRow.put("dispcomponentid", entity.getName());
            mapRow.put("component",entity.getName());
        }
        if (mapRow.get("orgcode") != null) {
            temp = mapRow.get("orgcode").toString();
            StringBufferProxy wheresql = new StringBufferProxy();
            wheresql.appendSingle("1=1");
            wheresql.appendSingle("and code = '{0}'",temp);
            List<CboOrgEntity> cboOrgEntities = cboOrgService.queryByWhere(wheresql.toString());
            mapRow.put("disporgcode", cboOrgEntities.get(0).getName());
            mapRow.put("orgname", cboOrgEntities.get(0).getName());
        }
        if (mapRow.get("rolecode") != null) {
            temp = mapRow.get("rolecode").toString();
            StringBufferProxy wheresql = new StringBufferProxy();
            wheresql.appendSingle("1=1");
            wheresql.appendSingle("and code = '{0}' ",temp);
            List<CboRoleEntity> cboRoleEntities = cboRoleService.queryByWhere(wheresql.toString());
            mapRow.put("disprolecode",cboRoleEntities.get(0).getName());
            mapRow.put("rolename",cboRoleEntities.get(0).getName());
        }
    }
}
